Imports System.Data.SqlClient

Friend Class DBBlockLog
    Inherits DBBase

    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub Load( _
        ByRef oObject As SQLAutoDocLib.BlockLog)

        Dim sSQL As String = "select"
        sSQL = sSQL & "     [DatabaseID],"
        sSQL = sSQL & "     [SessionID],"
        sSQL = sSQL & "     [Blocked_SPID],"
        sSQL = sSQL & "     [Blocked_Status],"
        sSQL = sSQL & "     [Blocked_HostName],"
        sSQL = sSQL & "     [Blocked_ProgramName],"
        sSQL = sSQL & "     [Blocked_Command],"
        sSQL = sSQL & "     [Blocked_LoginName],"
        sSQL = sSQL & "     [Blocking_SPID],"
        sSQL = sSQL & "     [Blocking_Status],"
        sSQL = sSQL & "     [Blocking_HostName],"
        sSQL = sSQL & "     [Blocking_ProgramName],"
        sSQL = sSQL & "     [Blocking_Command],"
        sSQL = sSQL & "     [Blocking_LoginName],"
        sSQL = sSQL & "     [CreateDate]"
        sSQL = sSQL & " from"
        sSQL = sSQL & "     BlockingHistory"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        Dim oData As DataTable = MyBase.ExecuteReadToDataTable(sSQL)

        If oData.Rows.Count > 0 Then
            With oData.Rows(0)
                oObject.DatabaseID = .Item("DatabaseID")
                oObject.SessionID = .Item("SessionID")

                oObject.Blocked_SPID = .Item("Blocked_SPID")
                oObject.Blocked_Status = .Item("Blocked_Status")
                oObject.Blocked_HostName = .Item("Blocked_HostName")
                oObject.Blocked_Program_Name = .Item("Blocked_Program_Name")
                oObject.Blocked_Command = .Item("Blocked_Command")
                oObject.Blocked_LoginName = .Item("Blocked_LoginName")

                oObject.Blocking_SPID = .Item("Blocking_SPID")
                oObject.Blocking_Status = .Item("Blocking_Status")
                oObject.Blocking_HostName = .Item("Blocking_HostName")
                oObject.Blocking_Program_Name = .Item("Blocking_Program_Name")
                oObject.Blocking_Command = .Item("Blocking_Command")
                oObject.Blocking_LoginName = .Item("Blocking_LoginName")

                oObject.CreateDate = .Item("CreateDate")
            End With
        End If

        oData.Dispose()
    End Sub

    Public Sub Add(ByRef oObject As SQLAutoDocLib.BlockLog)

        Dim sSQL As String = "insert into BlockingHistory ("
        sSQL = sSQL & "     [ID],"
        sSQL = sSQL & "     [DatabaseID],"
        sSQL = sSQL & "     [SessionID],"

        sSQL = sSQL & "     [Blocked_SPID],"
        sSQL = sSQL & "     [Blocked_Status],"
        sSQL = sSQL & "     [Blocked_HostName],"
        sSQL = sSQL & "     [Blocked_ProgramName],"
        sSQL = sSQL & "     [Blocked_Command],"
        sSQL = sSQL & "     [Blocked_LoginName],"

        sSQL = sSQL & "     [Blocking_SPID],"
        sSQL = sSQL & "     [Blocking_Status],"
        sSQL = sSQL & "     [Blocking_HostName],"
        sSQL = sSQL & "     [Blocking_ProgramName],"
        sSQL = sSQL & "     [Blocking_Command],"
        sSQL = sSQL & "     [Blocking_LoginName],"

        sSQL = sSQL & "     [CreateDate]) values ("

        sSQL = sSQL & ValueToDBValue(oObject.ID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.DatabaseID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.SessionID) & ","

        sSQL = sSQL & ValueToDBValue(oObject.Blocked_SPID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Blocked_Status, 50) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Blocked_HostName, 50) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Blocked_Program_Name, 50) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Blocked_Command, 50) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Blocked_LoginName, 50) & ","

        sSQL = sSQL & ValueToDBValue(oObject.Blocking_SPID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Blocking_Status, 50) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Blocking_HostName, 50) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Blocking_Program_Name, 50) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Blocking_Command, 50) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Blocking_LoginName, 50) & ","

        sSQL = sSQL & ValueToDBValue(oObject.CreateDate) & ")"

        MyBase.ExecuteNonQuery(sSQL)
    End Sub

    Public Sub Delete(ByRef oObject As SQLAutoDocLib.BlockLog)
        Dim sSQL As String = "delete from BlockingHistory"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        MyBase.ExecuteNonQuery(sSQL)
    End Sub
End Class
